function queryCar(){
    $("#car_dialog").dialog("open");
    $("#car_dialog").dialog("setTitle","车辆信息");
    $("#car_datagrid").datagrid({
        fit:true,
        url:"/car/list",
        fitColumns:true,
        striped:true,
        pagination:true,
        singleSelect:true,
        rownumbers:true,
        onDblClickRow: function(index,row){
            row["car.displacement"] = row.displacement;
            row["car.carname"] = row.carname;
            row["car.cartype"] = row.cartype;
            row["car.marketval"] = row.marketval;
            row["car.sort"] = row.sort;
            row["car.carsizeId"] = row.carsizeId;
            row["car.id"] = row.id;
            $("#car_Form").form("load",row);
            $("#car_dialog").dialog("close");
        },
        columns:[[
            {field:'id',title:'编号', hidden:true},
            {field:'checkbox',checkbox:true,tilte:'选中',width:100},
            {field:'carname',title:'车俩品牌',align:'center',width:100},
            {field:'cartype',title:'车辆型号',align:'center',width:100},
            {field:'displacement',title:'排气量/L',align:'center',width:100},
            {field:'marketval',title:'排气量/L',align:'center',width:100},
            {field:'carsizeId',title:'分类',align:'center',width:100,formatter:function(value){
                if(value==1){
                    return "小型"
                }else if(value==2){
                    return "中型"
                }else if(value==3){
                    return "大型"
                }
            }},
            {field:'sort',title:'车载大小',align:'center',width:100,formatter:function(value){
                if(value){
                    return "<p style='color: #00bbee'>载人</p>";
                }else{
                    return "<p style='color: #e68900'>载物</p>";
                }
            }},
        ]],})

    }
$(function(){
    $("#car_dialog").dialog({
        width:750,
        height:400,
        closable:true,
        closed:true

    })
})
//----------------------------------------
$(function(){
    $("#my_dialog").dialog({
        width:500,
        height:500,
        buttons:"#bb",
        closable:true,
        closed:true
    })
})
function searchs(){

    $("#my_dialog").dialog("open");
    $("#my_dialog").dialog("setTitle","投保人信息");

    $("#my_datagrid").datagrid({
        url:"/client/querys?state=1",
        fitColumns: true,
        fit: true,
        pagination:true,
        rownumbers: true,
        striped: true,
        columns:[[
            {field: 'ck', checkbox: true},
            {field:'id',title:'编号', hidden:true},
            {field:'clientname',title:'客户姓名',width:100},
            {field:'gender',title:'性别',align:'center',width:100,formatter:function(value,row){
                if(value == 1){
                    return "男";
                }else{
                    return "女";
                }
            }},
            {field:'idcard',title:'身份证',align:'center',width:100},
            {field:'tel',title:'联系方式',align:'center',width:100},
            {field:'address',title:'通讯地址',align:'center',width:100}
        ]]
    })
}
function add(){
    var row = $("#my_datagrid").datagrid("getSelected");
    if(!row){
        $.messager.alert('温馨提示','请选择需要编辑的行');
        return;
    }
    $("#editForm").form("load",row);
    $("#my_dialog").dialog("close");

}
function safes(){
    $("#car_dialog").dialog("open");
    $("#car_dialog").dialog("setTitle","产品信息");
    var row = $("#institution").val();
    $("#car_datagrid").datagrid({
        fit:true,
        url:"/productInfo/queryProductForaiId?id="+row,
        fitColumns:true,
        striped:true,
        pagination:true,
        singleSelect:true,
        rownumbers:true,
        onDblClickRow: function(index,row) {
            row["product_id"] = row.id;
            $("#info_form").form("load", row);
            $("#car_dialog").dialog("close");
            $("#in_datagrid").datagrid({
                fit:true,
                fitColumns:true,
                striped:true,
                pagination:true,
                singleSelect:true,
                rownumbers:true,
                columns: [[
                    {field: 'ck', checkbox: true},
                    {field: 'id', title: '编号', hidden: true, width: 100},
                    {field: 'sn', title: '保险编码', width: 100, align: 'right'},
                    {field: 'name', title: '产品名称', width: 100},
                    {
                        field: 'agency', title: '所属机构', width: 100, formatter: function (value, row, index) {
                        return value? value.name:"";
                    }
                    },
                    {field: 'limityear', title: '保障年限', width: 100},
                    {field: 'insurance', title: '保额', width: 100},
                    {field: 'annualfee', title: '年费', width: 100, align: 'right'},
                    {
                        field: 'state', title: '状态', width: 100, align: 'right',formatter: function (value, row, index) {

                        if (value == 1) {
                            return "<font style='color: green'>在售</font>";
                        } else if (value == 0) {
                            return "<font style='color: red'>停售</font>";
                        }
                    }
                    },
                    {
                        field: 'deduction', title: '不计免赔', width: 100, align: 'right',formatter: function (value, row, index) {

                        if (value == 1) {
                            return "<font style='color: green'>是</font>";
                        } else if (value == 0) {
                            return "<font style='color: red'>否</font>";
                        }
                    }
                    },

                ]],

            })
            $("#in_datagrid").datagrid('appendRow',row);
        },
        columns: [[
            {field: 'ck', checkbox: true},
            {field: 'id', title: '编号', hidden: true, width: 100},
            {field: 'sn', title: '保险编码', width: 100, align: 'right'},
            {field: 'name', title: '产品名称', width: 100},
            {
                field: 'agency', title: '所属机构', width: 100, formatter: function (value, row, index) {
                return value? value.name:"";
            }
            },
            {field: 'limityear', title: '保障年限', width: 100},
            {field: 'insurance', title: '保额', width: 100},
            {field: 'annualfee', title: '年费', width: 100, align: 'right'},
            {
                field: 'state', title: '状态', width: 100, align: 'right',formatter: function (value, row, index) {

                if (value == 1) {
                    return "<font style='color: green'>在售</font>";
                } else if (value == 0) {
                    return "<font style='color: red'>停售</font>";
                }
            }
            },
            {
                field: 'deduction', title: '不计免赔', width: 100, align: 'right',formatter: function (value, row, index) {

                if (value == 1) {
                    return "<font style='color: green'>是</font>";
                } else if (value == 0) {
                    return "<font style='color: red'>否</font>";
                }
            }
            },

        ]],})
}

$(function(){
    $("#year").numberbox({
        min:0,
        precision:2,
        onChange:function(){
            var year = $("#year").val();
            var rows = $("#in_datagrid").datagrid('getRows');
            var num = 0;
            $.each( rows, function(i, n){
                num = num + n.annualfee;
            });
            num = num * year;
            $("#totalAmount").text(num);
        }
    });

})
function hold(){
    $("#car_Form").form('submit', {
        url:"/storages/saveCar",
        success:function(data){
            $("#editForm").form("submit",{
                url:"/storages/saveClient",
                success:function(data){
                    $("#info_form").form('submit', {
                        url:"/storages/saveSafe",
                        onSubmit: function(param){
                            param.limit = $("#totalAmount").text();
                        },
                        success:function(data){
                            $.messager.alert("温馨提示","操作成功")
                            $("#car_Form").form("reset");
                            $("#editForm").form("reset");
                            $("#info_form").form("reset");
                            $("#in_datagrid").datagrid('loadData', { total: 0, rows: [] });


                        }
                    });
                }
            })
        }
    });



}